import joblib
import pandas as pd
from sklearn.metrics import roc_auc_score
from sklearn.metrics import precision_score
from sklearn.metrics import recall_score
from GBDT_train import init,preprocess
from utils.log import Logger
logging_obj = Logger(root_path="../",log_name="predict")
logger = logging_obj.get_logger()

def predict(df):
    logger.info('开始预测')
    x = df.drop(columns=['Attrition'])
    y = df['Attrition']
    model = joblib.load('../model/model.pkl')
    transformer = joblib.load('../model/transformer.pkl')
    x = transformer.transform(x)
    y_predict = model.predict(x)
    y_predict_proba = model.predict_proba(x)[:, 1]
    logger.info(f"准确率: {model.score(x, y)}")
    logger.info(f"AUC分数: {roc_auc_score(y, y_predict_proba)}")
    logger.info(f"精确率: {precision_score(y, y_predict)}")
    logger.info(f"召回率: {recall_score(y, y_predict)}")
    logger.info('预测完毕')





if __name__ == '__main__':
    init_data = init('../data/test2.csv')
    df = preprocess(init_data)
    predict(df)
